import { blackTokenList } from "./../database/config.js";

// 检查黑名单, token已由jwtConfig校验了, 这里只需要检查是否在黑名单中
const checkBlackToken = async (ctx, next) => {
    const { authorization } = ctx.request.header;
    if (authorization) {
        const token = authorization.split(' ')[1];
        if (blackTokenList.has(token)) {
            ctx.status = 401;
            ctx.body = {
                success: false,
                msg: "token已失效",
            };
            return;
        }
    }
    await next();
};

export default checkBlackToken;
